﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using CoffeePotServer;
using System.Threading;
using System.Diagnostics;

namespace Server
{
    class Program
    {
        static void Main(string[] args)
        {
            HTCPCPServer thisServer;
            if(args.Length == 0)Console.WriteLine("Usage <port> <numberOfPots>");
            else
            {
                try
                {
                    thisServer = new HTCPCPServer(Convert.ToInt32(args[0]));
                    for (int intCount = 0; intCount < Convert.ToInt32(args[1]); intCount++)
                    {
                        thisServer.AddNewPot();
                    }
                    Console.WriteLine("Server started on {0}",
                                      args[0]);
                    Thread serverStart = new Thread(thisServer.StartListening);
                    serverStart.Start();
                    String strInput = "";
                    while(strInput != "x")
                    {
                        if (strInput == "d")
                        {
                            HTCPCPServer.DebugMode = !HTCPCPServer.DebugMode;
                            Console.WriteLine("Verbose output: {0}", HTCPCPServer.DebugMode);
                        }
                        strInput = Console.ReadLine();
                    }
                    thisServer.StopListening();
                }
                catch (InvalidCastException ex)
                {
                    Console.WriteLine("Usage <port> <numberOfPots>");
                    Trace.WriteLine(ex.Message);
                }
            }
        }
    }
}
